<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <link rel="stylesheet" th:href="@{/static/element/index.css}"/>
</head>
<style>
    body {
        scroll: "no";
        scroll: "auto";
        overflow-x: hidden;
        overflow-y: hidden;
    }
</style>
<body>
<div id="app">
    <template>
        <el-form :model="queryForm" ref="queryForm" :inline="true">
            <el-form-item label="表名" prop="tableName">
                <el-input clearable
                          size="small"
                          @keyup.enter.native="handleQuery" v-model="queryForm.tableName"
                          placeholder="请输入表名称"></el-input>
            </el-form-item>

            <el-form-item label="表描述" prop="tableComment">
                <el-input clearable
                          size="small"
                          @keyup.enter.native="handleQuery" v-model="queryForm.tableComment"
                          placeholder="请输入表描述"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">清空</el-button>
            </el-form-item>
        </el-form>

        <el-row>
            <el-col>


                <el-button type="primary"
                           style="margin-left: 1%"
                           icon="el-icon-circle-plus"
                           size="mini" @click="handleImportTable">导入
                </el-button>
            </el-col>
        </el-row>


        <el-table
                v-loading="loading"
                element-loading-text="加载中"
                element-loading-spinner="el-icon-loading"
                :data="tableData" row-key="id"
                :header-cell-style="{'text-align':'center','color':'grey','font-weight':'600'}"
                :cell-style="{'text-align':'center'}" border style="margin-top: 10px"
                @selection-change="handleSelectionChange"

        >
            <el-table-column
                    type="selection"
                    width="40">
            </el-table-column>
            <el-table-column prop="tableName" label="表名" show-overflow-tooltip=""></el-table-column>
            <el-table-column prop="tableComment" label="表描述" show-overflow-tooltip="true"></el-table-column>

            <el-table-column prop="createTime" label="创建时间"></el-table-column>


        </el-table>

        <el-pagination
                background
                :page-sizes="[10, 20, 30, 40,50]"
                layout="total, sizes, prev, pager, next, jumper"
                :total="total"
                :page-size.sync="pageSize"
                :current-page.sync="currentPage"
                @size-change="handleQuery"
                @current-change="handleQuery"
                style="float: right;margin-top: 10px"
        />

        <div style="text-align: center;margin-top: 5%">
            <el-button size="small" @click="closePage">取 消</el-button>
            <el-button size="small" type="primary" @click="handleSubmit">确 定</el-button>
        </div>
    </template>
</div>
</body>
<script th:src="@{/static/js/axios.min.js}"></script>
<script th:src="@{/static/js/request.js}"></script>
<script th:src="@{/static/js/common.js}"></script>
<script th:src="@{/static/api/gen.js}"></script>
<script th:src="@{/static/js/vue.min.js}"></script>
<script th:src="@{/static/element/index.js}"></script>
<script th:src="@{/static/js/jquery.min.js}"></script>
<script th:src="@{/static/layer/layer.js}"></script>
<script>
    new Vue({
        el: '#app',
        data() {
            return {
                queryForm: {},
                tableData: [],
                multipleSelection: [],
                currentPage: 1,
                pageSize: 10,
                total: 0,
                loading: false,
            }
        },
        created() {
            this.handleQuery()
        },
        methods: {
            handleSelectionChange(val) {

                this.multipleSelection = val;
                console.log(this.multipleSelection)
            },
            handleImportTable() {
                let params = {}
                if (this.multipleSelection.length === 0) {
                    this.$notify({
                        title: '失败',
                        message: '请选择导入表',
                        duration: 2000
                    });
                    return
                }

                params.tableNames = this.multipleSelection.map((item) => item.tableName)
                requests.post('tool/table/importTable', params).then(res => {
                    if (res.code === '200') {
                        this.$notify({
                            title: '成功',
                            message: '导入成功',
                            type: 'success'
                        });
                        setTimeout(() => {
                            let index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        }, 200)
                    }
                })
            },
            resetQuery() {
                this.queryForm = {}
                this.handleQuery()
            },
            handleQuery() {
                this.loading = true
                let queryParam = {}
                queryParam.pageNo = this.currentPage;
                queryParam.pageSize = this.pageSize;
                queryParam.tableName = this.queryForm.tableName;
                queryParam.tableComment = this.queryForm.tableComment;
                tableList(queryParam).then(res => {
                    if (res.code === '200') {
                        this.tableData = res.data.list
                        this.total = Number(res.data.count);
                        this.loading = false
                    } else {
                        this.loading = false
                    }
                });
            },
            handleSubmit() {
                addOrUpdate('/sys/menu/add', this);
                this.expandStatus = true
            }
        }
    });
</script>
</html>
